package cn.dnui_xcz826.dnuifood_16110100826.fragments;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;
import cn.dnui_xcz826.dnuifood_16110100826.R;
import cn.dnui_xcz826.dnuifood_16110100826.adapter.ShopAdapter;
import cn.dnui_xcz826.dnuifood_16110100826.bean.ShopBean;
import cn.dnui_xcz826.dnuifood_16110100826.listener.onRetrofitListener;
import cn.dnui_xcz826.dnuifood_16110100826.model.ShopModel;

public class Fragment1 extends BaseFragment implements onRetrofitListener<List<ShopBean>> {
    //private List<ShopBean> list;
   // private LinearLayoutManager layoutManager;
    private RecyclerView recyclerView;
    private ShopAdapter adapter;
    //private int page=1; // 代表页数，并初始化为1，代表第1页。
    //private int lastVisibleItemPosition;//最后一条可见条目的位置

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        initData();
//        initViews();
        view=inflater.inflate(R.layout.activity_fragment1,container,false);
        recyclerView=(RecyclerView) view.findViewById(R.id.rw);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        return view;

    }
    void initData(){
        ShopModel shopModel=new ShopModel();
        shopModel.getAllShops(this);
    }

    @Override
    public void onSuccess(List<ShopBean> object, int flag) {
        adapter=new ShopAdapter(getActivity(),object);
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void onFailure(String msg) {
        Toast.makeText(getActivity(),"网络错误",Toast.LENGTH_SHORT).show();
    }

    @Override
    void initViews() {

    }

    @Override
    void initEvents() {

    }
}
